<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>表格渲染</title>
  </head>
  <body>
    <table border="1" cellspacing="0">
      <thead>
        <tr>
          <th>学号</th>
          <th>姓名</th>
          <th>年龄</th>
          <th>性别</th>
        </tr>
      </thead>
    </table>
    <script>
      var userList = [
        { id: 1, name: 'Jack', age: 18, gender: '男' },
        { id: 2, name: 'Rose', age: 20, gender: '女' },
        { id: 3, name: 'Tom', age: 22, gender: '男' },
        { id: 4, name: 'Jerry', age: 24, gender: '女' },
      ];
      var tableEl = document.querySelector('table');
      var tbodyEl = document.createElement('tbody');
      tableEl.append(tbodyEl);
      for (var i = 0; i < userList.length; i++) {
        var trEl = document.createElement('tr');
        var obj = userList[i];
        for (var index in obj) {
          var tdEl = document.createElement('td');
          tdEl.textContent = obj[index];
          trEl.append(tdEl);
        }
        tbodyEl.append(trEl);
      }
    </script>
  </body>
</html>
